﻿using AiXiu.BLL;
using AiXiu.Common;
using AiXiu.IBLL;
using AiXiu.Model;
using System;
using System.Web.UI;

namespace AiXiu.WebSite
{
    public partial class Mobile : Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnLogin_Click(object sender, EventArgs e)
        {
            if(Page.IsValid)
            {
                // 登录验证
                string mobileNumber = txtMobileNumber.Text;
                string password = txtPassword.Text;
                IAccountManager userManager = new AccountManager();
                OperResult<TBUsers> operResult = userManager.LoginByMobileNumber(mobileNumber, password);
                if (operResult.StatusCode == StatusCode.Succeed)
                {
                    // 缓存用户资料
                    TBUsers user = operResult.ReadResult();
                    IdentityManager.SaveUser(user);
                    // 脚本跳转
                    string redirectUrl = Request.QueryString["ReturnUrl"];
                    if(string.IsNullOrWhiteSpace(redirectUrl))
                    {
                        redirectUrl = "Default.aspx";
                    }
                    this.Redirect("lgnsuccess", redirectUrl);
                }
                else
                {
                    this.Alert("lgnfail", operResult.Message ?? "登录失败！");
                }
            }
        }
    }
}